package com.learn.demo.ioc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 静态变量注入
 *
 * @author banjiawei
 * @date 2022/02/24
 */
@Component
@Slf4j
public class TestStaticIoc1 {
    private static String a;
    private static String b;

    @Value("${test.static.a}")
    public void setA(String a) {
        TestStaticIoc1.a = a;
    }

    @Value("${test.static.b}")
    public void setB(String b) {
        TestStaticIoc1.b = b;
    }

    @PostConstruct
    public void init(){
        log.info("a={}", a);
        log.info("=====================静态变量注入1=====================");
        log.info("b={}", b);
        TestStaticIoc1 testStaticIoc1 = new TestStaticIoc1();
        log.info("testStaticIoc1 is {}", testStaticIoc1);
    }

    @Override
    public String toString() {
        return "TestStaticIoc1{" +
                "a='" + a + '\'' +
                ", b='" + b + '\'' +
                '}';
    }
}
